package com.atzwc.aop.xml.aspect;


import com.atzwc.aop.annotation.utils.LoggerUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * Date:2020/9/25
 * Author:ybc
 * Description:
 */
@Component
public class LoggerAspect {


    public void beforeAdviceMethod(JoinPoint joinPoint){
        LoggerUtils.showMethodNameAndArgs(joinPoint.getSignature().getName(), joinPoint.getArgs());
    }

    public void afterAdviceMethod(){
        System.out.println("后置通知-->finally");
    }

    public void afterReturningAdviceMethod(JoinPoint joinPoint, Object result){
        LoggerUtils.showMethodNameAndResult(joinPoint.getSignature().getName(), result);
    }

    public void afterThrowingAdviceMethod(JoinPoint joinPoint, Exception ex){
        LoggerUtils.showMethodNameAndExceptionMessage(joinPoint.getSignature().getName(), ex.getMessage());
    }

    public Object aroundAdviceMethod(ProceedingJoinPoint joinPoint){
        Object object = null;
        try {
            System.out.println("Around-->前置");
            object = joinPoint.proceed();
            System.out.println("Around-->返回通知");
        } catch (Throwable throwable) {
            System.out.println("Around-->异常通知");
            throwable.printStackTrace();
        } finally {
            System.out.println("Around-->后置通知");
        }
        return object;
    }

}
